<?php

use Core\Controller;
use Core\Exception;
use Service\AlidayuService;
use Log\SeasLog;
use Service\ResponseService;
use  Helper\ArrayHelper;
class DemoController extends Controller
{


    public function init()
    {
        parent::init();
        if(!DEBUG){
            $this->redirect('/mobile/index/index');
            return false;
        }
    }

    /**
     * 抛出异常
     * 备注：控制器层，逻辑层请统一交给常报错处理错误
     * @throws
     */
    public function expAction()
    {
        // 根据错误表提示信息
//        throw new Exception(10100);
        // 手动修改错误信息
//        throw new Exception(10100,'错误提示',[],'debug错误提示');
        // 移动端可以带跳转页面(站内、站外跳转均可)
        throw new Exception(10100,'带跳转页面',['redirectUrl' => 'index/index/index'],'debug错误提示');
    }

    /**
     * 打日志
     */
    public function logAction()
    {
        /**
         * 写一条日志（不要用error_log）
         * 一般打日志用于测试，所以统一用debug，还有error，notice等，具体参考psr-3
         */
        SeasLog::debug('debug日志');
        return false;
    }

    /**
     * 获取请求参数
     * Request类（$this->request）
     */
    public function requestAction()
    {
        $server = $this->request->getServer();
        $get = $this->request->get();
        $post = $this->request->post();
        $id = $this->request->post('id');
        $sessionId = $this->request->getSession('id');
    }

    /**
     * 数据返回
     * APP和移动端页面返回都有一点不同，比如APP还要返回token，建议基类根据情况再封装一层
     */
    public function responseAction()
    {
        // 统一json返回
        ResponseService::json(1,'提示信息',['ttt' => 123]);
        // 页面渲染
        ResponseService::view($this,['title' => '木头云']);
    }


    /**
     * 阿里大于短信发送
     * @throws
     */
    public function alidayuAction()
    {
        $ret = AlidayuService::send('13827299724','smstest', ['customer' => '鸡翅木2']);
        dump($ret);
        die();
    }

    /**
     * token解密
     */
    /**
     * @return String
     */
    public function tokenVerifyAction()
    {
        $token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvbS5tdXRvdXl1bi5jbiIsImF1ZCI6IjMyNjM0IiwiZXhwIjoxNTc4NTY1MzA0LCJpYXQiOjE1Nzc5NjA1MDR9.kM_D_ZoZXwyNMAX_4Ag2gTlD7-LoTQBzoZfP6eKkUBE-mojg-M0jRMzceFLFIOElsFxhYekX-JG3ktSKSBUryK-dAeSajXTbZTSeVuGCF7Ywj26HHX4zumD_xKqgxcNmt_Ll3ZL1I36rH5FBZKhTYSorwXUNQda2d2uq9p1wHp4';
        $data = \Service\AppTokenService::getPayloadByToken($token);
        dump($data);
        die();


    }




}